package com.ybkj.o2o.zhuanxian.common;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;
import java.util.Date;

public class CustomDateSerializer extends JsonSerializer<Date> {

  private static final Logger logger = LoggerFactory.getLogger(CustomDateSerializer.class);

  @Override
  public void serialize(Date value, JsonGenerator jsonGenerator, SerializerProvider provider) {
    try {
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      jsonGenerator.writeString(sdf.format(value));
    } catch (Exception ex) {
      logger.error("CustomerDateSerializer:{}",ex);
    }

  }
}
